package com.aix.demo;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

@RestController
@EnableAutoConfiguration



public class HelloController {

    @RequestMapping("/")
    public String home() {
        return "Hello World!123123asdasd";
    }
    @RequestMapping("/123")
    public String home123() {
        return "Hello World!123123asdasdasdasdasd我的天";
    }
    @RequestMapping("/dd")
    public ArrayList<String> hhhh()  {
        ArrayList list=null;
        try {
           list=selectColumn();
        }catch (Exception e){

        }


        return list;
    }


    @RequestMapping("/php")
    public ArrayList<String> selectColumn() throws SQLException {
        Statement statement = null;
        ResultSet resultSet = null;
        ArrayList<String> list=new ArrayList<String>();
        try {
            DruidDataSource dataSource = new DruidDataSource();
            dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
            dataSource.setUsername("user");
            dataSource.setPassword("123456");
            dataSource.setUrl("jdbc:mysql://192.168.0.9/beego?characterEncoding=UTF-8");
            Connection connection = dataSource.getConnection();
            statement = connection.createStatement();
            resultSet = statement.executeQuery("select * from user LIMIT 10 ");


            while (resultSet.next()) {

                list.add(resultSet.getString("username"));
                System.out.println(resultSet.getString("username"));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }


        return list;


    }
    public static void main(String[] args) throws Exception {
        SpringApplication.run(HelloController.class, args);
    }
}
